package com.fengmi.controller;

import com.fengmi.dto.PageDTO;
import com.fengmi.entity.MallGoodsSpec;
import com.fengmi.entity.MallGoodsSpecOptions;
import com.fengmi.service.GoodsSpecOptionsService;
import com.fengmi.vo.PageResultVO;
import com.fengmi.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 123
 * @Date 2022/1/25 9:39
 * @Version 1.0
 */

@RestController
@CrossOrigin
@RequestMapping("spec")
@Api(tags = "规格管理")
public class GoodsSpecOptionsController {

    @Autowired
    private GoodsSpecOptionsService specOptionsService;

    @RequestMapping("page")
    @ApiOperation("分页查询")
    public PageResultVO<MallGoodsSpecOptions> page(@RequestBody @ApiParam("分页条件实体类") PageDTO<MallGoodsSpecOptions> pageDTO) {
        return specOptionsService.findSpecOptionsByPage(pageDTO);
    }

    @PostMapping("save")
    @ApiOperation("添加功能")
    public ResultVO save(@RequestBody MallGoodsSpec mallGoodsSpec) {
        //System.out.println(mallGoodsSpec);

        return specOptionsService.saveSpecAndSpecOptions(mallGoodsSpec);
    }

    @GetMapping("findOne/{id}")
    @ApiOperation("查询规格选项，做数据回显")
    public ResultVO findOneById(@PathVariable String id) {
        return specOptionsService.selectOneBySpecOptionsId(id);
    }

    @GetMapping("findAll")
    @ApiOperation("查询所有规格信息")
    public ResultVO findAll() {
        return specOptionsService.selectAllSpec();
    }

    @PutMapping
    @ApiOperation("修改规格选项")
    public ResultVO updateSpecOptions(@RequestBody MallGoodsSpecOptions specOptions ) {
        return specOptionsService.updateOptions(specOptions);
    }

    @DeleteMapping("{id}")
    @ApiOperation("删除规格选项")
    public ResultVO delOptions(@PathVariable String id) {
        return specOptionsService.deleteOneById(id);
    }

}